using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using VSSDKAssist.Assets.CustomPages;
using Microsoft.Practices.WizardFramework;
using Microsoft.VisualStudio.Shell;
using VSSDKAssist.Recipes.Common.Editors;
using VSSDKAssist.Recipes.Common.Converters;

namespace VSSDKAssist.Recipes.CreateVSToolWindow
{
	/// <summary>
	/// Custom page for CreateVSToolWindow recipe
	/// </summary>
	public partial class CreateVSToolWindowCP3 : WizardPageBase
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="CreateVSToolWindowCP3"/> class.
		/// </summary>
		public CreateVSToolWindowCP3()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="CreateVSToolWindowCP3"/> class.
		/// </summary>
		/// <param name="wizard">The <see cref="T:Microsoft.Practices.WizardFramework.WizardForm"/>that will host the new page.</param>
		public CreateVSToolWindowCP3(WizardForm wizard)
			: base(wizard)
		{
			InitializeComponent();
		}

		/// <summary>
		/// Gets or sets the window GUID.
		/// </summary>
		/// <value>The window GUID.</value>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "value"), RecipeArgument]
		public Guid WindowGuid
		{
			get { return (Guid)veWindowGUID.Value; }
			set
			{
			}
		}

		/// <summary>
		/// Gets or sets the UI context GUID.
		/// </summary>
		/// <value>The UI context GUID.</value>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "value"), RecipeArgument]
		public Guid UIContextGuid
		{
			get { return (Guid)veUIContextGUID.Value; }
			set
			{
			}
		}

		/// <summary>
		/// Gets or sets the dock style.
		/// </summary>
		/// <value>The dock style.</value>
		[RecipeArgument]
		public VsDockStyle DockStyle
		{
			get { return (VsDockStyle)veDockStyle.Value; }
			set
			{
				veDockStyle.TextBox.Text = value.ToString();
			}
		}

		/// <summary>
		/// Gets or sets the orientation.
		/// </summary>
		/// <value>The orientation.</value>
		[RecipeArgument]
		public ToolWindowOrientation Orientation
		{
			get { return (ToolWindowOrientation)veOrientation.Value; }
			set
			{
				veOrientation.TextBox.Text = value.ToString();
			}
		}
		/// <summary>
		/// Gets or sets a value indicating whether [multi instances].
		/// </summary>
		/// <value><c>true</c> if [multi instances]; otherwise, <c>false</c>.</value>
		[RecipeArgument]
		public bool MultiInstances
		{
			get { return (Boolean)veMultiInstances.Value; }
			set
			{
				veMultiInstances.TextBox.Text = value.ToString();
			}
		}
		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="CreateVSToolWindowCP3"/> is transient.
		/// </summary>
		/// <value><c>true</c> if transient; otherwise, <c>false</c>.</value>
		[RecipeArgument]
		public bool Transient
		{
			get { return (Boolean)veTransient.Value; }
			set
			{
				veTransient.TextBox.Text = value.ToString();
			}
		}

		/// <summary>
		/// Gets or sets the site of the control.
		/// </summary>
		/// <value></value>
		/// <returns>The <see cref="T:System.ComponentModel.ISite"></see> associated with the <see cref="T:System.Windows.Forms.Control"></see>, if any.</returns>
		/// <PermissionSet><IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/><IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
		public override ISite Site
		{
			get
			{
				return base.Site;
			}
			set
			{
				base.Site = value;
				if(value != null)
				{
					this.veUIContextGUID.BeginInit();
					this.veUIContextGUID.ValueType = typeof(Guid);
					base.Site.Container.Add(veUIContextGUID);
					this.veUIContextGUID.EditorInstance = new UIContextGuidEditor();
					this.veUIContextGUID.ConverterInstance = new UIContextGuidConverter();
					this.veUIContextGUID.EndInit();

					this.veWindowGUID.BeginInit();
					this.veWindowGUID.ValueType = typeof(Guid);
					base.Site.Container.Add(veWindowGUID);
					this.veWindowGUID.EditorInstance = new WindowGuidEditor();
					this.veWindowGUID.ConverterInstance = new WindowGuidConverter();
					this.veWindowGUID.EndInit();

					this.veDockStyle.BeginInit();
					this.veDockStyle.ValueType = typeof(VsDockStyle);
					base.Site.Container.Add(veDockStyle);
					this.veDockStyle.ConverterInstance = new EnumConverter(typeof(VsDockStyle));
					this.veDockStyle.EndInit();

					this.veTransient.BeginInit();
					this.veTransient.ValueType = typeof(Boolean);
					base.Site.Container.Add(veTransient);
					this.veTransient.ConverterInstance = new BooleanConverter();
					this.veTransient.EndInit();

					this.veOrientation.BeginInit();
					this.veOrientation.ValueType = typeof(ToolWindowOrientation);
					base.Site.Container.Add(veOrientation);
					this.veOrientation.ConverterInstance = new EnumConverter(typeof(ToolWindowOrientation));
					this.veOrientation.EndInit();

					this.veMultiInstances.BeginInit();
					this.veMultiInstances.ValueType = typeof(Boolean);
					base.Site.Container.Add(veMultiInstances);
					this.veMultiInstances.ConverterInstance = new BooleanConverter();
					this.veMultiInstances.EndInit();
				}
			}
		}

		private void veUIContextGUID_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			Guid guid = (Guid)veUIContextGUID.Value;
			DictionaryService.SetValue("UIContextGuid", guid);
		}

		private void veWindowGUID_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			Guid guid = (Guid)veWindowGUID.Value;
			DictionaryService.SetValue("WindowGuid", guid);
		}

		private void veDockStyle_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			VsDockStyle dockStyle = (VsDockStyle)veDockStyle.Value;
			DictionaryService.SetValue("DockStyle", dockStyle);
		}

		private void veMultiInstances_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			Boolean multiInstances = (Boolean)veMultiInstances.Value;
			DictionaryService.SetValue("MultiInstances", multiInstances);
		}

		private void veOrientation_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			ToolWindowOrientation orientation = (ToolWindowOrientation)veOrientation.Value;
			DictionaryService.SetValue("Orientation", orientation);
		}

		private void veTransient_ValueChanged(object sender, System.ComponentModel.Design.ComponentChangedEventArgs e)
		{
			Boolean transient = (Boolean)veTransient.Value;
			DictionaryService.SetValue("Transient", transient);
		}
	}
}